import { defineStore } from 'pinia'
import { ref } from 'vue'

// 用户模块
export const useUserStore = defineStore(
  'orange-template',
  () => {
    const token = ref('') // 定义 token
    const setToken = (t) => (token.value = t) // 设置 token
    const userInfo = ref({
      id: '',
      username: '',
      auth: '',
      avatar: ''
    }) // 定义用户信息
    const setUserInfo = (id,username,auth,avatar) => {
      userInfo.value.id = id
      userInfo.value.username = username
      userInfo.value.auth = auth
      userInfo.value.avatar = avatar
    }
    const removeToken = () => {
      token.value = ''
    }
    const removeUserInfo = () => {
      userInfo.value = {
        id: '',
        username: '',
        auth: '',
        avatar: ''
      }
    }
    return { token, setToken, removeToken, userInfo, setUserInfo, removeUserInfo }
  },
  {
    persist: true // 持久化
  }
)
